﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Base.DAL;
using Base.BLL;
using Base.Util;
using System.ComponentModel;
using System.Data;
using MPSystem.Models;
using MPSystem.Controllers;

namespace MPSystem.Views.YFQ
{
    /// <summary>
    /// DP_test_Condition5.xaml 综采数据分析--查询条件
    /// </summary>
    public partial class DataQuery_ZCAnalysis_Conditon : Page
    {
        public Dictionary<string, string> Cond = new Dictionary<string, string>();
        public static DataQuery_ZCAnalysis_Conditon _Me = null;
        public static DataQuery_ZCAnalysis_Conditon Me
        {
            get
            {
                if (_Me == null)
                {
                    _Me = new DataQuery_ZCAnalysis_Conditon();
                    _Me.UpdateCond();
                }
                return _Me;
            }
            set { _Me = value; }
        }
        int gzmbh = 0;

        public DataQuery_ZCAnalysis_Conditon()
        {
            InitializeComponent();
            LoadData();
            Me = this;
        }

        public void LoadData()
        {
            #region 加载加权
            string strJQ = "2&2H,4&4H,8&8H,12&12H,24&24H";
            string[] arJQ = strJQ.Split(',');
            DataTable tempTable = new DataTable();
            DataColumn dc1 = new DataColumn("bh", Type.GetType("System.Int32"));
            DataColumn dc2 = new DataColumn("mc", Type.GetType("System.String"));
            tempTable.Columns.Add(dc1);
            tempTable.Columns.Add(dc2);
            foreach (var r in arJQ)
            {
                string[] arrl = r.ToString().Split('&');
                DataRow dr0 = tempTable.NewRow();
                dr0["bh"] = int.Parse(arrl[0]);
                dr0["mc"] = arrl[1].ToString();
                tempTable.Rows.Add(dr0);
            }
            tempTable.AcceptChanges();
            CB_Jq.ItemsSource = tempTable.DefaultView;
            tempTable.Dispose();
            #endregion

            #region 加载单位选择
            string strP = "MPa,KN";
            string[] arP = strP.Split(',');
            foreach (var ar in arP)
            {
                CB_DW.Items.Add(ar);
            }
            CB_DW.SelectedIndex = 0;
            #endregion

            LoadBH();
            BegTime.SelectedDate = DateTime.Now;
            EndTime.SelectedDate = DateTime.Now;
        }

        #region 读取压力分站编号
        public void LoadBH()
        {
            if (gzmbh == DataQuery_ZCAnalysisController.gzmbh) return;

            gzmbh = DataQuery_ZCAnalysisController.gzmbh;
            var li_ylfz = ConfigService.GetZcWz(gzmbh);
            Items = new Dictionary<string, object>();
            var select = new Dictionary<string, object>();
            if (li_ylfz.Count() > 0)
            {
                foreach (var r in li_ylfz)
                {
                    Items.Add(r.YLFJBH.ToString(), r.YLFJBH.ToString());
                    select.Add(r.YLFJBH.ToString(), r.YLFJBH.ToString());
                }
            }
            MC.ItemsSource = Items;
            MC.SelectedItems = select;

        }
        #endregion

        public void UpdateCond()
        {
            Cond.Clear();
            try
            {
                string str_List = "";
                foreach (var item in MC.SelectedItems.Keys)
                {
                    if (str_List == "")
                        str_List = item.ToString();
                    else
                        str_List += "," + item.ToString();
                }
                Cond.Add("bhs", str_List);
                Cond.Add("dtStart", BegTime.Text);
                Cond.Add("dtEnd", EndTime.Text);
                Cond.Add("jq", CB_Jq.SelectedValue.ToString());
                Cond.Add("page", "0");
                Cond.Add("perPage", "20");
                Cond.Add("MPa", CB_DW.SelectedValue.ToString());
            }
            catch { }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {            
            this.CloseParentWindow();

        }
        #region 多选下拉框使用
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private Dictionary<string, object> _items;
        private Dictionary<string, object> _selectedItems;
        public Dictionary<string, object> Items
        {
            get
            {
                return _items;
            }
            set
            {
                _items = value;
                NotifyPropertyChanged("Items");
            }
        }
        public Dictionary<string, object> SelectedItems
        {
            get
            {
                return _selectedItems;
            }
            set
            {
                _selectedItems = value;
                NotifyPropertyChanged("SelectedItems");
            }
        }
        private void Submit()
        {
            foreach (KeyValuePair<string, object> s in SelectedItems)
                MessageBox.Show(s.Key);
        }
        #endregion
    }
}
